using System;

namespace Nvigorate.Repository
{
    public abstract class BaseFetchStrategy<TModel> : IFetchStrategy<TModel>
        where TModel : class
    {
        public abstract string GetExpansionPath();
    }

    public abstract class BaseFetchStrategy<TModel, TDTO> : BaseFetchStrategy<TModel>, IFetchStrategy<TModel, TDTO>
        where TModel : class
        where TDTO : class
    {
        private ITranslator<TModel, TDTO> _translator;
        protected ITranslator<TModel, TDTO> Translator { get { return _translator; } }

        public virtual TDTO GetDTO(TModel model)
        {
            return Translator.Get(model);
        }

        public virtual void UpdateModel(TModel model, TDTO dto)
        {
            Translator.GetUpdateStrategy(model)(dto);
        }

        public virtual TModel CreateModel(TDTO dto)
        {
            return Translator.GetCreateStrategy()(dto);
        }

        protected BaseFetchStrategy()
        {
            _translator = new DefaultTranslator<TModel, TDTO>();
        }

        protected BaseFetchStrategy(ITranslator<TModel, TDTO> translator)
        {
            _translator = translator;
        }
    }
}